package cn.hy.shortUrl.manager;

import cn.hy.shortUrl.entity.UrlMap;
import cn.hy.shortUrl.entity.UrlMapExample;
import cn.hy.shortUrl.mapper.UrlMapMapper;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class UrlMapManager {

    @Resource
    private UrlMapMapper urlMapMapper;

    public String getLongUrlByKey(String key) {
        UrlMapExample example = new UrlMapExample();
        example.createCriteria().andSortUrlEqualTo(key);
        List<UrlMap> urlMaps = urlMapMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(urlMaps)) {
            return null;
        }
        return urlMaps.get(0).getLongUrl();
    }
}
